﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Safe_Driving.TokenUser;
using System.Windows;
using System.Windows.Controls;

namespace Safe_Driving
{
    public partial class MainWindow
    {
        private void initScore()
        {
            SingletonTokenUser token = SingletonTokenUser.GetInstance();
            AppSafeDriving app = (AppSafeDriving)token.DbApp;

            IEnumerable<SFInSCrIt> inscrit = (from c in app.SFInSCrIt where c.IDClient == 1 select c);
            dataGridCours.ItemsSource = inscrit;

        }

#region AjouterNote

        /// <summary>
        /// Ajouter une note sur le cour selectioné dans la datagrid datagridCours
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAjouterNote_Click(object sender, RoutedEventArgs e)
        {
            SingletonTokenUser token = SingletonTokenUser.GetInstance();
            AppSafeDriving app = (AppSafeDriving)token.DbApp;

            SFInSCrIt addInscrit = new SFInSCrIt();
            addInscrit.IDClient = token.Client_selected.IDClient;

            addInscrit = (SFInSCrIt)dataGridCours.SelectedItem;
            
            addInscrit.Note = (short)cbNoteDuCour.SelectedItem;
            /////////////////////BUG//////////////////////////////////////////

            app.SFInSCrIt.InsertOnSubmit(addInscrit);

            app.SubmitChanges();

            //On réinitialise la datagrid
            IEnumerable<SFInSCrIt> inscrit = (from c in app.SFInSCrIt where c.IDClient == 1 select c);
            dataGridCours.ItemsSource = inscrit;
          
        }

        private void dataGridCours_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
        ////    SingletonTokenUser token = SingletonTokenUser.GetInstance();
        ////    AppSafeDriving app = (AppSafeDriving)token.DbApp;

        ////    SFInSCrIt addInscrit = new SFInSCrIt();
        ////    addInscrit.IDClient = token.Client_selected.IDClient;

        ////    addInscrit = (SFInSCrIt)dataGridCours.SelectedItem;
        ////    tbDebutCour.Text = addInscrit.DateDebut.ToString();
        ////    tbFinCour.Text = addInscrit.DateFIn.ToString();
        ////    cbNoteDuCour.SelectedItem = addInscrit.Note;
       }



#endregion
    }
}
